import { defineStore } from "pinia";
import {loginApi} from '@/apis/user.js';
import { reactive , ref } from 'vue';
import {useCartStore} from '@/stores/cartStore'


export const useUserStore = defineStore('user',() => {

  const userInfo = ref({})
  const cartStore = useCartStore()


  const getUserInfo = async ({account,password}) => {

    const res = await loginApi({account,password})
    userInfo.value = res.result
    //合并购物车
    cartStore.mergeCart()
  }

  const claearInfo = () => {
    userInfo.value = {}
    // 购物车数据清空
    cartStore.clearCar()
  }

  return {
    userInfo,
    getUserInfo,
    claearInfo
  }


},{
  persist: true
})
